package com.sakura.util.java8;

import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Arrays;

/**
 * Created by apple on 2018/7/9.
 */
public class Test {
    /**
     * 测试输出
     */
    public static void test1(){
        Arrays.asList( "a", "b", "d" ).forEach( e -> System.out.println( e ) );
        Arrays.asList( "a", "b", "d" )
                .forEach((String e) -> System.out.println( e ) );

        Arrays.asList("a", "b", "c").forEach(e -> {
            System.out.println(e);
            System.out.println(e);
        });
    }

    /**
     * 测试类成员和局部变量
     */
    public static  void test2(){
        String separator = ",";
        Arrays.asList("a", "b", "c").forEach(
                (String e) -> {
                    System.out.println(e + separator);
                }
        );
    }

    /**
     * lambda表达式中的返回值
     */
    public static void test3(){
        Arrays.asList("a", "b", "c").sort((e1, e2) -> e1.compareTo(e2));

        Arrays.asList("a", "b", "c").sort((e1, e2) -> {
            int result = e1.compareTo(e2);
            return result;
        });

    }

    /**
     * 测试时间类
     */
    public static void testTime(){
        final Clock clock = Clock.systemUTC();
        System.out.println( clock.instant() );
        System.out.println( clock.millis() );

        // Get the local date and local time
        final LocalDate date = LocalDate.now();
        final LocalDate dateFromClock = LocalDate.now( clock );

        System.out.println( date );
        System.out.println( dateFromClock );

// Get the local date and local time
        final LocalTime time = LocalTime.now();
        final LocalTime timeFromClock = LocalTime.now( clock );

        System.out.println( time );
        System.out.println( timeFromClock );

    }


    public static void main(String[] args) {
        //test1();
        //test2();
        //test3();
        //testTime();
        DefaultableImpl defaultable = new DefaultableImpl();
        System.out.println(defaultable.notRequired());
    }
}
